﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BaHuan.BusinessLayer;
using BaHuan.Common;
using BaHuan.DataLayer;
using BaHuan.Entities;
namespace BaHuan
{
    public partial class FrmTimKiemDoiTruThue : Form
    {
        private DoiTruThue doitruthue = new DoiTruThue();
        private DoiTruThueManagement doitruthueMgt = new DoiTruThueManagement();

        
        public FrmTimKiemDoiTruThue()
        {
            InitializeComponent();
        }

        public List<DoiTruThue> GetAllDoiTruThue()
        {
            ResultObj resultObj = new ResultObj();
            resultObj = doitruthueMgt.GetAllDoiTruThue();
            List<DoiTruThue> lstPhieutruthue = (List<DoiTruThue>)resultObj.Result;
            return lstPhieutruthue;

        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;
            DateTime dtTuNgay =  dtpTuNgay.Value;
            DateTime dtDenNgay = dtpDenNgay.Value;

            List<DoiTruThue> lstDoiTruThue = (from mh in GetAllDoiTruThue()
                                           where (mh.MaSo.ToLower().Contains(txtMaSo.Text.ToLower()))
                                           && mh.NgayThang.Date >= dtTuNgay.Date && mh.NgayThang.Date <= dtDenNgay.Date
                                        select mh).ToList();

            dataGridView1.DataSource = lstDoiTruThue;

        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmTimKiemDoiTruThue_Load(object sender, EventArgs e)
        {
            dataGridView1.ReadOnly = true;
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            FrmKhauTruThueBuoc1 frm = new FrmKhauTruThueBuoc1();
            this.Hide();
            frm.ShowDialog();
            this.Show();
        }
    }
}
